<extend name="Manage/themes/default/base" />
<block name="main">
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <table class="table-form">
                    <tr>
                        <td width="100" align="right" class="td-title">
                            <span class="x-red">*</span>名称：
                        </td>
                        <td>
                            <input id="name" value="{{$info['name']??''}}" class="layui-input" size="40">
                        </td>
                    </tr>

                    <tr>
                        <td width="100" align="right" class="td-title">
                            <span class="x-red">*</span>编号：
                        </td>
                        <td>
                            <input id="code" value="{{$info['code']??''}}" class="layui-input" size="40">
                            <span class="x-red">(4个字符，字母和数字组成)</span>
                        </td>
                    </tr>


                    <tr>
                        <td width="100" align="right" class="td-title">
                            <span class="x-red"></span>说明：
                        </td>
                        <td>
                            <textarea id="describe" cols="100" rows="7" style="resize: none">{{$info['describe']??''}}</textarea>
                        </td>
                    </tr>


                    <tr>
                        <td></td>
                        <td>
                            <button class="layui-btn layui-btn-danger layui-btn-lg" onclick="Pages.sureSave()" type="button">确定保存</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <script>
        var form;
        var id = parseInt({{$id??0}});

        layui.use(['form'], function(){
            form = layui.form;
        });

        var Pages = {
            canOperate:true, //能否操作
            sureSave:function(){
                if(!Pages.canOperate){
                    return false;
                }
                var param = {};
                param.name= $("#name").val();
                param.code= $("#code").val();
                param.describe = $('#describe').val();

                var loading = VK.load();
                var method = id >0 ? 'PUT':'POST';
                var url = id>0 ? VK.U('modules/'+id):VK.U('modules');
                Pages.canOperate = false;
                VK.QAjax(url,method,param,function (res) {
                    VK.closeLoad(loading);
                    if (res.status != 200){
                        Pages.canOperate = true;
                        VK.error(res.msg);
                        return false;
                    }
                    VK.success(res.msg);
                    setTimeout(function(){
                        VK.nofifyParentPage("reloadList");
                        VK.closeNowPage();
                    },1500);
                },function (res) {
                    VK.closeLoad(loading);
                    Pages.canOperate = true;
                    VK.error('系统出错稍后再试');
                });
            }
        }

    </script>
</block>